package modellstadt.testapplets;

import java.util.ArrayList;

import modellstadt.geom.Face;
import modellstadt.geom.FaceQuad;
import peasy.PeasyCam;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PMatrix3D;
import processing.core.PVector;


public class TestAppletExtrude extends PApplet{
	FaceQuad quad;
	PeasyCam cam;
	public void setup(){
		size(800,600,P3D);
		quad=new FaceQuad(new PVector(-100,0,-100),new PVector(200,0,-100),new PVector(100,0,100),new PVector(-100,0,100));
		quad.rotateX(20);
		quad.rotateZ(-20);
		quad.rotateY(40);
		
		PMatrix3D pm=quad.getMatrixXY();
		quad.transform(pm);
		cam=new PeasyCam(this,300);
	}
	
	
	public void draw(){
		background(0);
		drawWorldAxis3D(g,200);
		fill(255,0,0);
		quad.rotateX(0.02f);
		quad.rotateZ(0.01f);
		quad.display3D(g);
		fill(255);
		ArrayList<Face> extrudes=quad.extrude(new PVector(100,0,100));
		for (int i=0;i<extrudes.size();i++){
			Face f=extrudes.get(i);
			f.display3D(g);
		}
		Face roof=extrudes.get(4);
		Face[] roofFaces=roof.pointLoftCenter(mouseY);
		fill(0,255,0);
		for (int i=0;i<roofFaces.length;i++){
			Face f=roofFaces[i];
			f.display3D(g);
		}
	}
	
	public static void  drawWorldAxis3D(PGraphics pg,float scale){
		pg.pushStyle();
		pg.stroke(255,0,0);
		pg.line(0,0,0,scale,0,0);
		pg.stroke(0,255,0);
		pg.line(0,0,0,0,scale,0);
		pg.stroke(0,0,255);
		pg.line(0,0,0,0,0,scale);
		pg.popStyle();
	}
	
}

